package com.na.onlineservey.project


import com.docu.common.Action
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import com.na.onlineservey.Project
import com.na.onlineservey.ProjectService

@Component("createProjectAction")
class CreateProjectAction extends Action {

  @Autowired
  ProjectService projectInstanceService

  public Object preCondition(Object params, Object object) {
    try {
      Project projectInstance = (Project) object
      if (!projectInstance.validate()) {
        return null
      }
      return projectInstance
    } catch (Exception ex) {
    log.error(ex.message)
      return null
    }
  }

  public Object execute(Object params, Object object) {
    try {
      return projectInstanceService.create(object)
    } catch (Exception ex) {
    log.error(ex.message)
      return null
    }
  }

  public Object postCondition(Object params, Object object) {
    return null
  }
}